package cn.mysocketnet.a05tcpdemo1;

import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) {
        //TCP协议，发送数据

        //1.创建Socket对象
        //细节：在创建对象的同时会连接服务端
        //      如果连接不上，代码会报错
        try(Socket socket = new Socket("127.0.0.1", 10000)){
            //2.可以从连接通道中获取输出流
            OutputStream os = socket.getOutputStream();
            //写出数据
            os.write("你好你好".getBytes());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
